<?php

	// The file
	$filename = $_GET['filename'];
	
	// Content type
	header('Content-Type: image/jpeg');
	
	// Get new dimensions
	list($width, $height) = getimagesize($filename);
	$new_width = null;
	$new_height = null;
	if(isset($_GET['width']) && isset($_GET['height'])){
		$new_width = $_GET['width'];
		$new_height = $_GET['height'];
	} elseif(isset($_GET['width'])){
		$new_width = $_GET['width'];
		$new_height = $height * ($new_width / $width);
	} else {
		$new_height = $_GET['height'];
		$new_width = $width * ($new_height / $height);
	}
	
	// Resample
	$image_p = imagecreatetruecolor($new_width, $new_height);
	$image = imagecreatefromjpeg($filename);
	imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
	
	// Output
	imagejpeg($image_p, null, 100);
	
?>